import React, {useState} from 'react'
import { Image, Button, View } from 'react-native'
import * as ImagePicker from 'expo-image-picker';

const Draft = () => {
    const [imageUrl, setImageUrl] = useState("");
    const pickImage = async ()=>{
        let result = await ImagePicker.launchImageLibraryAsync({
            mediaTypes: ImagePicker.MediaTypeOptions.All,
            allowsEditing: true,
            aspect: [4, 3],
            quality: 1,
          });
      
          console.log(result);
      
          if (!result.canceled) {
            setImageUrl(result.assets[0].uri);
          }
    }
    return (
        <View>
            <Button 
                title='选择图片'
                onPress={pickImage}
            />
            {
                imageUrl 
                    && <Image 
                        source={{uri: imageUrl}}
                        style={{width: 100,height: 100}}
                    />
            }
        </View>
    )
}

export default Draft